<?php

// +----------------------------------------------------------------------
// | 文件 DeviceEvent.class.php
// +----------------------------------------------------------------------
// | 说明 设备相关的接口
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

namespace Api\Event;
use Api\Event\Cache\DeviceRemEvent;

class DeviceEvent extends BaseEvent
{

	const MAX_SCORE = 100;

	// 根据类型, 和型号来判断分值
	static public function calculateType($type, $model)
	{
		$lists  = DeviceRemEvent::get($type);
		$config = DeviceRemEvent::get_score($type);
		$model = trim($model);
		// 如果不存在列表或者没有配置则为最大 
		if (!array_key_exists($model, $lists) || !$config){
			return self::MAX_SCORE;
		}

		$model_score = $lists[$model]; // 现在型号所在的zlist的值  值越小 对应的分值越大
		$rates = $config['rate'];
		ksort($rates); 
		$model_rate = end($rates);
 		foreach ($rates as $score => $rate) {
			if ($model_score <= $score){
				$model_rate = $rate;
 				break;
			}
 		}
		return $model_rate;
	}

}